package com.zisu.rabbitproducer.component;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2021/5/11 20:24
 */
@Configuration
public class ReturnBackSender implements RabbitTemplate.ReturnCallback{
    //rabbitTemplate.setReturnCallback 会调用这个接口
    //第二种publisher-returns模式，该模式会在消息没有被路由到queues时将消息返回
    @Override
    public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        System.out.println("消息未能成功路由到指定queues");
        System.out.println("return--message:" + new String(message.getBody()) + ",replyCode:" + replyCode
                + ",replyText:" + replyText + ",exchange:" + exchange + ",routingKey:" + routingKey);

    }
}
